package com.packagetracker.helpers;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;

import com.packagetracker.entities.Settings;
import com.packagetracker.providers.TrackerProviderSetup;

public class SettingsHelper {
	
	private Activity activity;
	
	public SettingsHelper(final Activity activity) {
		this.activity = activity;
	}
	
	public Settings getSettings() {
		final Cursor cursor = this.activity.getContentResolver().query(TrackerProviderSetup.Settings.CONTENT_URI, new String[] { TrackerProviderSetup.Settings.MAP_TYPE }, null, null, null);
		final int typeIndex = cursor.getColumnIndex(TrackerProviderSetup.Settings.MAP_TYPE);
		final Settings settings = new Settings();
		
		while (cursor.moveToNext()) {
			settings.setMapType(cursor.getInt(typeIndex));
		}
		
		return settings;
	}
	
	public void update(final ContentValues values) {
		this.activity.getContentResolver().update(TrackerProviderSetup.Settings.CONTENT_URI, values, null, null);
	}
	
}